<!DOCTYPE html>
<!-- saved from url=(0052)http://getbootstrap.com/docs/4.0/examples/dashboard/ -->
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>综合实践项目管理系统</title>
    <!-- Bootstrap core CSS -->
    <link href="../static/asserts/css/bootstrap.min.css" th:href="@{../static/asserts/css/bootstrap.min.css}" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="../static/asserts/css/dashboard.css" th:href="@{../static/asserts/css/dashboard.css}" rel="stylesheet">
    <style type="text/css">
        /* Chart.js */

        @-webkit-keyframes chartjs-render-animation {
            from {
                opacity: 0.99
            }
            to {
                opacity: 1
            }
        }

        @keyframes chartjs-render-animation {
            from {
                opacity: 0.99
            }
            to {
                opacity: 1
            }
        }

        .chartjs-render-monitor {
            -webkit-animation: chartjs-render-animation 0.001s;
            animation: chartjs-render-animation 0.001s;
        }
    </style>
</head>

<body>
<!--引入抽取的顶部文件-->
<div th:replace="commons/common :: top"></div>

<div class="container-fluid">
    <div class="row">
        <!--引入侧边栏-->
        <div th:replace="commons/common::#left"></div>
        <main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
            <h2>修改企业信息</h2>
            <div class="form-inline">
                <form th:action="@{/adminFindCom}" method="post" >
                    <input name="teaName" type="text" placeholder="名字">
                    <input type="submit" value="查询">
                </form>
            </div>
            <div class="table-responsive">
                <table class="table table-striped table-sm">
                    <thead>
                    <tr>
                        <th></th>
                        <th>企业编号</th>
                        <th>企业名</th>
                        <th>联系电话</th>
                        <th></th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody id="teas" name="teas">
                    <tr th:each="user:${users}">
                        <td><input type="checkbox" name="checkId" th:value="${user.id}"></td>
                        <td th:text="${user.id}"></td>
                        <td th:text="${user.username}"></td>
                        <td th:text="${user.phone}"></td>
                        <td>
                        <td class="btn btn-sm btn-primary" th:onclick="updateComInfo([[${user.id}]]);">编辑</td>
                        <td class="btn btn-sm btn-danger"  th:onclick="deleteComInfo([[${user.id}]]);">删除</td>
                        </td>
                    </tr>
                    </tbody>
                </table>

                <tr>
                    <td><button th:onclick="page(1)">首页</button></td>
                    <td><button th:onclick="page(-1)">上一页</button></td>
                    <td><button th:onclick="page(-2)">下一页</button></td>
                    <td><button th:onclick="page(0)">尾页</button></td>
                </tr>
                <input type="hidden" id="pages" th:value="${pages}">
                <input type="hidden" id="nowPages" th:value="1">

            </div>
        </main>
    </div>
</div>

<!-- 模态框（Modal） -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <form th:action="@{/adminUpdateComInfo}" method="post" onsubmit="return checkData()">
            <div class="modal-content">
                <div class="modal-header">
                    <h4 class="modal-title" id="myModalLabel">
                        企业用户管理
                    </h4>
                </div>
                <div class="modal-body">
                    <input type="hidden" id="teaid" name="id">
                    用户名:&nbsp;&nbsp;<input id="teaname" name="username" type="text"  readonly><br>
                    联系方式:<input id="teaphone" name="phone" type="text"><br>
                </select>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                    </button>
                    <button type="submit" class="btn btn-primary">
                        提交
                    </button>
                </div>
            </div><!-- /.modal-content -->
        </form>
    </div><!-- /.modal -->
</div>

<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script type="text/javascript" src="../static/login/js/jquery-3.4.1.min.js" th:src="@{../static/login/js/jquery-3.4.1.min.js}"></script>
<script type="text/javascript" src="../static/asserts/js/popper.min.js" th:href="@{../static/asserts/js/popper.min.js}"></script>
<script type="text/javascript" src="../static/asserts/js/bootstrap.min.js" th:href="@{../static/asserts/js/bootstrap.min.js}"></script>

<!-- Icons -->
<script type="text/javascript" src="../static/asserts/js/feather.min.js" th:href="@{../static/asserts/js/feather.min.js}"></script>
<script>
    feather.replace()
</script>

<!-- Graphs -->
<script type="text/javascript" src="../static/asserts/js/Chart.min.js" th:href="@{../static/asserts/js/Chart.min.js}"></script>

<script>
    function updateComInfo(data) {
        var id = data;
        $.ajax({
            url:"/adminFindTeacher",
            type:"post",
            data:{id:id},
            success: function (data) {  //回调函数  执行完请求后执行函数
                document.getElementById("teaid").value = data.id;
                document.getElementById("teaname").value = data.username;
                document.getElementById("teaphone").value = data.phone;
                $('#myModal').modal('show');
            },
            error:function(data){
                alert("失败！！");
            }
        })
    }

    function deleteComInfo(data){
        if (!confirm("确定要删除吗?")) {
            return false;
        }
        var id = data;
        $.ajax({
            url:"/deleteTeaInfo",
            type:"post",
            data:{id:id},
            success: function (data) {  //回调函数  执行完请求后执行函数
                alert("删除成功！！！");
                window.location.reload();
            },
            error:function(data){
                alert("失败！！");
            }
        })
    }
</script>
<script>
    function page(data){
        if(1 == data){   //首页
            data = data;
            document.getElementById("nowPages").value = data;
            alert("当前已是第一页！！！");
        }
        if(-1 == data){  // 上一页
            data = document.getElementById("nowPages").value;
            if(1 == data){
                alert("当前已是第一页！！！");
                data = 1;
            }else{
                data = data - 1 ;
                document.getElementById("nowPages").value = data;
            }

        }
        if(-2 == data){   //下一页
            data = document.getElementById("nowPages").value;
            var pages = document.getElementById("pages").value;  // 最后一页
            if(pages == data){
                alert("当前已是最后一页！！！");
            }else{
                data = parseInt(data) + 1;
                document.getElementById("nowPages").value = data;
            }
        }
        if(0 == data){
            data = document.getElementById("pages").value;
            document.getElementById("nowPages").value = data;
            alert("当前已是最后一页！！！");
        }
        $.ajax({
            url:"/compage",
            type:"post",
            data:{pagenum:data},
            success: function (data) {  //回调函数  执行完请求后执行函数
                var html = "";
                for(var i=0;i<data.length;i++){
                    var da = data[i];
                    html+="<tr>";
                    html+="<td><input type=\"checkbox\"></td>";
                    html+="<td>"+da.id+"</td>";
                    html+="<td>"+da.username+"</td>";
                    html+="<td>"+da.phone+"</td>";
                    html+="<td>";
                    //           html+="<a class=\"btn btn-sm btn-primary\" href=\"user/"+da.id+"\">编辑</a>";
                    html+="<td class=\"btn btn-sm btn-primary\" onclick=\"updateComInfo("+da.id+");\">编辑</td>";
                    //           html+="<a class=\"btn btn-sm btn-danger\" href=\"user/"+da.id+"\">删除</a>";
                    html+="<td class=\"btn btn-sm btn-danger\" onclick=\"deleteComInfo("+da.id+");\">删除</td>";
                    html+="</td>";
                    html+="</tr>";
                }
                $("#teas").html(html);
            },
            error:function(data){
                alert("失败！！");
            }
        })
    }

    function checkData() {
        var regphone = document.getElementById("teaphone").value;

        if("" == regphone ){
            alert("必填项不能为空！！！");
            return false;
        }
        var TEL_REGEXP = /^1([38]\d|5[0-35-9]|7[3678])\d{8}$/;
        if(!TEL_REGEXP.test(regphone)){
            alert("请输入正确的电话号码");
            return false;
        }
        return true;
    }
</script>
</body>
</html>